//
//  MyViewController.m
//  Yu01
//
//  Created by 蒋松涵 on 16/8/19.
//  Copyright © 2016年 蒋松涵. All rights reserved.
//

#import "MyViewController.h"
#import "MessageViewController.h"

//我的签到
#import "MyAttendanceVC.h"
//我的查寝
#import "MyKnowingViewController.h"
//我的请假
#import "AskLeaveVC.h"
//我的建议
#import "MyAdviceViewController.h"
//账号信息
#import "AccountMessageViewController.h"
//关于
#import "AboutViewController.h"
//
#import "LoginModel.h"

//
#import "ChengJiViewController.h"
#import "XuanKeViewController.h"

@interface MyViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView * _tableView;
}

@property (nonatomic,strong)NSString * nameLabel;
@property (nonatomic,strong)NSString * schoolLabel;
@property (nonatomic,strong)NSString * XiBuLabel;

@property (nonatomic,retain) NSString *urlStr;
@property (nonatomic,retain) NSDictionary *urlParameters;
@property (nonatomic,strong)NSMutableArray * dataArray;
@end

@implementation MyViewController



//请求数据
- (void)fecthDataFromNet:(NSString *)url parameters:(NSDictionary *)parameter {
    
    NSLog(@"%@",url);
    NSLog(@"%@",parameter);
    //初始化请求工具
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:url parameters:parameter progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];

        NSLog(@"学生信息-%@",dic);
        LoginModel * loginM = [[LoginModel alloc]init];
        [loginM setValuesForKeysWithDictionary:dic[@"info"]];
        self.nameLabel = loginM.loginName;
        self.schoolLabel = loginM.title;
        self.XiBuLabel = loginM.code;
        [_tableView reloadData];
        NSLog(@"%@",loginM);
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        
    }];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    _urlStr = @"http://www.100xsys.com.cn/school/app/studentInfo/getInfoJson";
    _urlParameters = [[NSDictionary alloc]initWithObjectsAndKeys:@"1",@"appWebConfigId",@"xuesheng1",@"studentInfo.loginName", nil];
    
    [self fecthDataFromNet:_urlStr parameters:_urlParameters];
    
//    self.dataArray = [[NSMutableArray alloc]init];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.barTintColor = [UIColor orangeColor];
    
    //导航栏字体颜色
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    //修改导航栏添加的按钮（item）颜色
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
    
    
    [self _tableview];
//    [self tableHeaderView];
}

// tableView
-(void)_tableview
{
    CGFloat h = 736 / ScreenHeight;
//    CGFloat w = 414 / ScreenWidth;

    _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource =self;
    //去掉多余的表（线）
    _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
//    _tableView.rowHeight = 60/h;
    [self.view addSubview:_tableView];
}
//自定义表头
-(void)tableHeaderView
{
    CGFloat h = 736 / ScreenHeight;
    CGFloat w = 414 / ScreenWidth;


    
    UIView * _tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 100/h)];
    _tableHeaderView.backgroundColor = [UIColor colorWithRed:174/255.0 green:209/255.0 blue:42/255.0 alpha:1];
    _tableView.tableHeaderView = _tableHeaderView;
    
    UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20/w, 10/h, 45/w, 45/h)];
    imageView.image = [UIImage imageNamed:@"header"];
    [_tableHeaderView addSubview:imageView];
    
    UILabel * headerLabel = [[UILabel alloc]initWithFrame:CGRectMake(20/w, 55/h, 80/w, 30/h)];
    headerLabel.text = @"修改头像";
    headerLabel.font = [UIFont systemFontOfSize:13/w];
    headerLabel.textColor = [UIColor whiteColor];
    [_tableHeaderView addSubview:headerLabel];
    
    UILabel * namelabel = [[UILabel alloc]initWithFrame:CGRectMake(100/w, 10/h, 100/w, 30/h)];
//    namelabel.text = @"张三";
    namelabel.text = [NSString stringWithFormat:@"%@",self.nameLabel];
    namelabel.textColor = [UIColor whiteColor];
    [_tableHeaderView addSubview:namelabel];

    UILabel * schoollabel = [[UILabel alloc]initWithFrame:CGRectMake(100/w, 35/h, 100/w, 30/h)];
//    schoollabel.text = @"西安工程大学";
    schoollabel.text = [NSString stringWithFormat:@"%@",self.schoolLabel];
    schoollabel.textColor = [UIColor whiteColor];
    [_tableHeaderView addSubview:schoollabel];
    
    UILabel * subjectlabel = [[UILabel alloc]initWithFrame:CGRectMake(100/w, 60/h, 100/w, 30/h)];
    subjectlabel.text = @"艺术设计学院";
    subjectlabel.textColor = [UIColor whiteColor];
    [_tableHeaderView addSubview:subjectlabel];
}
#pragma tableview代理方法
//
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat h = 736 / ScreenHeight;
    CGFloat w = 414 / ScreenWidth;

    
    static NSString * CellIdentifier = @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellAccessoryNone;
    
//    LoginModel * model = self.dataArray[indexPath.row];
    
    
    if (indexPath.row == 0)
    {
        cell.backgroundColor = [UIColor colorWithRed:174/255.0 green:209/255.0 blue:42/255.0 alpha:1];
        
        UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20/w, 10/h, 45/w, 45/h)];
        imageView.image = [UIImage imageNamed:@"8.30 新增图标导图-23"];
        [cell.contentView addSubview:imageView];
        
        UILabel * headerLabel = [[UILabel alloc]initWithFrame:CGRectMake(20/w, 55/h, 80/w, 30/h)];
        headerLabel.text = @"修改头像";
        headerLabel.font = [UIFont systemFontOfSize:13/w];
        headerLabel.textColor = [UIColor whiteColor];
        [cell.contentView addSubview:headerLabel];
        
        UILabel * namelabel = [[UILabel alloc]initWithFrame:CGRectMake(100/w, 10/h, 100/w, 30/h)];
        //    namelabel.text = @"张三";
        namelabel.text = [NSString stringWithFormat:@"%@",self.nameLabel];
        namelabel.textColor = [UIColor whiteColor];
        [cell.contentView addSubview:namelabel];
        
        UILabel * schoollabel = [[UILabel alloc]initWithFrame:CGRectMake(100/w, 35/h, 100/w, 30/h)];
        //    schoollabel.text = @"西安工程大学";
        schoollabel.text = [NSString stringWithFormat:@"%@",self.schoolLabel];
        schoollabel.textColor = [UIColor whiteColor];
        [cell.contentView addSubview:schoollabel];
        
        UILabel * subjectlabel = [[UILabel alloc]initWithFrame:CGRectMake(100/w, 60/h, 100/w, 30/h)];
//        subjectlabel.text = @"艺术设计学院";
        subjectlabel.text = self.XiBuLabel;
        subjectlabel.textColor = [UIColor whiteColor];
        [cell.contentView addSubview:subjectlabel];
        
        
    }
    else if (indexPath.row == 1)
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        //
        UIImageView * images = [[UIImageView alloc]initWithFrame:CGRectMake(10/w, 10/h, 35/w, 35/h)];
        images.image = [UIImage imageNamed:@"我的列表 图标95X95-01"];
        [cell.contentView addSubview:images];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(70/w, 15/h, 120/w, 30/h)];
        label.text = @"我的签到";
        [cell.contentView addSubview:label];
    }
    else if (indexPath.row == 2)
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        UIImageView * images = [[UIImageView alloc]initWithFrame:CGRectMake(10/w, 10/h, 35/w, 35/h)];
        images.image = [UIImage imageNamed:@"8.30 新增图标导图-01"];
        [cell.contentView addSubview:images];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(70/w, 15/h, 120/w, 30/h)];
        label.text = @"我的查寝";
        [cell.contentView addSubview:label];

    }
    else if (indexPath.row == 3)
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        UIImageView * images = [[UIImageView alloc]initWithFrame:CGRectMake(10/w, 10/h, 35/w, 35/h)];
        images.image = [UIImage imageNamed:@"我的列表 图标95X95-02"];
        [cell.contentView addSubview:images];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(70/w, 15/h, 120/w, 30/h)];
        label.text = @"我的请假";
        [cell.contentView addSubview:label];
    }
    else if (indexPath.row == 4)
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        UIImageView * images = [[UIImageView alloc]initWithFrame:CGRectMake(10/w, 10/h, 35/w, 35/h)];
        images.image = [UIImage imageNamed:@"我的列表 图标95X95-03"];
        [cell.contentView addSubview:images];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(70/w, 15/h, 120/w, 30/h)];
        label.text = @"成绩查询";
        [cell.contentView addSubview:label];

    }
    else if (indexPath.row == 5)
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        UIImageView * images = [[UIImageView alloc]initWithFrame:CGRectMake(10/w, 10/h, 35/w, 35/h)];
        images.image = [UIImage imageNamed:@"我的列表 图标95X95-04"];
        [cell.contentView addSubview:images];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(70/w, 15/h, 120/w, 30/h)];
        label.text = @"选修课";
        [cell.contentView addSubview:label];
    }
    else if (indexPath.row == 6)
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        UIImageView * images = [[UIImageView alloc]initWithFrame:CGRectMake(10/w, 10/h, 35/w, 35/h)];
        images.image = [UIImage imageNamed:@"我的列表 图标95X95-05"];
        [cell.contentView addSubview:images];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(70/w, 15/h, 120/w, 30/h)];
        label.text = @"校园圈";
        [cell.contentView addSubview:label];

    }
    else if (indexPath.row == 7)
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        UIImageView * images = [[UIImageView alloc]initWithFrame:CGRectMake(10/w, 10/h, 35/w, 35/h)];
        images.image = [UIImage imageNamed:@"我的列表 图标95X95-06"];
        [cell.contentView addSubview:images];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(70/w, 15/h, 120/w, 30/h)];
        label.text = @"账号信息";
        [cell.contentView addSubview:label];
    }
    else if (indexPath.row == 8)
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        UIImageView * images = [[UIImageView alloc]initWithFrame:CGRectMake(10/w, 10/h, 35/w, 35/h)];
        images.image = [UIImage imageNamed:@"8.30 新增图标导图-07"];
        [cell.contentView addSubview:images];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(70/w, 15/h, 120/w, 30/h)];
        label.text = @"我的建议";
        [cell.contentView addSubview:label];

    }
    else
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        UIImageView * images = [[UIImageView alloc]initWithFrame:CGRectMake(10/w, 10/h, 35/w, 35/h)];
        images.image = [UIImage imageNamed:@"我的列表 图标95X95-07"];
        [cell.contentView addSubview:images];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(70/w, 15/h, 120/w, 30/h)];
        label.text = @"关于";
        [cell.contentView addSubview:label];

    }
    
    return cell;
}
//区头高度
//-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
//{
//    return 1;
//}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat h = 736 / ScreenHeight;
    if (indexPath.row == 0)
    {
        return 100/h;
    }
    else
    {
        return 60/h;
    }
}

//
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        //无点击效果                       
    }
    else if (indexPath.row == 1)
    {
        //我的签到
        self.hidesBottomBarWhenPushed = YES;
        MyAttendanceVC * myAttendVC = [[MyAttendanceVC alloc]init];
        [self.navigationController pushViewController:myAttendVC animated:NO];
        self.hidesBottomBarWhenPushed = NO;
    }
    else if (indexPath.row == 2)
    {
        //我的查寝
        self.hidesBottomBarWhenPushed = YES;
        MyKnowingViewController * myKnowingVC = [[MyKnowingViewController alloc]init];
        [self.navigationController pushViewController:myKnowingVC animated:NO];
        self.hidesBottomBarWhenPushed = NO;
        
    }
    else if (indexPath.row == 3)
    {
        //我的请假
        self.hidesBottomBarWhenPushed = YES;
        AskLeaveVC * vc = [[AskLeaveVC alloc]init];
        [self.navigationController pushViewController:vc animated:NO];
        self.hidesBottomBarWhenPushed = NO;
    }
    else if (indexPath.row == 4)
    {
        //成绩查询
        self.hidesBottomBarWhenPushed = YES;
        ChengJiViewController * ChengJiVC = [[ChengJiViewController alloc]init];
        [self.navigationController pushViewController:ChengJiVC animated:YES];
        self.hidesBottomBarWhenPushed = NO;
    }
    else if (indexPath.row == 5)
    {
        //选修课
        self.hidesBottomBarWhenPushed = YES;
        XuanKeViewController * xuankeVC = [[XuanKeViewController alloc]init];
        [self.navigationController pushViewController:xuankeVC animated:YES];
        self.hidesBottomBarWhenPushed = NO;
    }
    else if (indexPath.row == 6)
    {
        //校友圈
    }
    else if (indexPath.row == 7)
    {
        //账号信息
        self.hidesBottomBarWhenPushed = YES;
        AccountMessageViewController * MessageVC = [[AccountMessageViewController alloc]init];
        [self.navigationController pushViewController:MessageVC animated:NO];
        self.hidesBottomBarWhenPushed = NO;
    }
    else if (indexPath.row == 8)
    {
        //我的建议
        self.hidesBottomBarWhenPushed = YES;
        MyAdviceViewController * MyAdviceVC = [[MyAdviceViewController alloc]init];
        [self.navigationController pushViewController:MyAdviceVC animated:YES];
        self.hidesBottomBarWhenPushed = NO;
    }
    else
    {
        //关于
        self.hidesBottomBarWhenPushed = YES;
        AboutViewController * aboutVC = [[AboutViewController alloc]init];
        [self.navigationController pushViewController:aboutVC animated:YES];
        self.hidesBottomBarWhenPushed = NO;
    }
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
